

#include "Solid.h"
#include "Containers.h"

namespace ouden {

namespace physics {

class PhysicsMgr
{
	
public:
	
	PhysicsMgr() 		{}
	~PhysicsMgr()
	{
		
		destroyAllSolids();
		
	}
	
	virtual void update();
	
	CSolid* createSolid(bool isStatic);
	
	void destroyAllSolids();
	
	void doCollisionDetection();
	
	//Level file contains already compiled table of shapes which are loaded into the actual table
	/*
	Loop dynamic
		s->doIntegration();
	Loop all
		collide
	*/
private:
	
	void collideDynamicWithStatic(CSolid* dynamicSolid, CSolid* staticSolid);
	
	Array<CSolid*> m_pSolids;			//Array of all solids
	Array<CSolid*> m_pDynamicSolids;	//Array of solids that can move
	
	//////////////////////////////////////////////
	//          Solid lookup table bits         //
	//                                          //
	typedef Array<CSolid*> SolidsSector;
	
	SolidsSector getNearbyStaticSolids(Vector pos);
	
	Scalar m_fSectorSize;
	Vector m_vSectorCount;
	
	//Spacial sorting structure updated every tick to hold moving solids
	Array< Array< SolidsSector > > m_DynamicSectorTable; 	//2D lookup table of dynamic solids in space
	
	//Spacial sorting structure populated once during load to hold static solids
	Array< Array< SolidsSector > > m_StaticSectorTable; 	//2D lookup table of static solids in space
	
	//                                           //
	//                                           //
	///////////////////////////////////////////////
	
};

} //namespace physics

} //namespace ouden
